﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace BallWar
{
    class Ball : Base
    {
        public bool Top { get; set; }
        public bool Left { get; set; }
        public bool Down { get; set; }
        public bool Right { get; set; }
        public Direction _direction { get; set; }
        public bool Moving { get; set; }
        public Ball(Color color, Point station, Graphics g)
        {
            _color = color;
            _station = station;
            _size = new Size(20, 20);
            _direction = Direction.East;
            _g = g;
            Moving = false;
            Top = false;
            Left = false;
            Down = false;
            Right = false;
        }
        public void CheckCollision(Size SenceSize)
        {
            if (_station.X <= 0) Left = true;
            if (_station.Y <= 0) Top = true;
            if (_station.X >= SenceSize.Width - _size.Width) Right = true;
            if (_station.Y >= SenceSize.Height - 2*_size.Width) Down = true;
            if (Left || Top || Right || Down)
            {
                Moving = false;
            }
            else
            {
                Moving = true;
            }
        }
        public void Grow()
        {
            _size = new Size(_size.Width + 1, _size.Height + 1);

        }
        public void Move()
        {
            this.UnDisplay();
            switch (_direction)
            {
                case Direction.East:
                    {
                        _station = new Point(_station.X + 2, _station.Y);
                        break;
                    }
                case Direction.West:
                    {
                        _station = new Point(_station.X - 2, _station.Y);
                        break;
                    }
                case Direction.North:
                    {
                        _station = new Point(_station.X, _station.Y - 2);
                        break;
                    }
                case Direction.South:
                    {
                        _station = new Point(_station.X, _station.Y + 2);
                        break;
                    }
            }
            this.Display();
        }
    }
    /// <summary>
    /// 移动的方向
    /// </summary>
    enum Direction
    {
        /// <summary>
        /// 向右
        /// </summary>
        East = 1,
        /// <summary>
        /// 向左
        /// </summary>
        West = 2,
        /// <summary>
        /// 向上
        /// </summary>
        North = 3,
        /// <summary>
        /// 向下
        /// </summary>
        South = 4
    }
}

